package com.lyshop.jinxiang.view;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.lyshop.jinxiang.R;


/**
 * Created by Administrator on 2018/1/19 0019.
 */

public class MyDialog extends Dialog {
    private int mGravity = Gravity.CENTER;
    public boolean isCancelAble = false;
    public Context mContext;

    public MyDialog(Context context) {
        this(context, false, Gravity.CENTER);
    }

    public MyDialog(Context context, boolean isCancelAble, int gravity) {
        super(context, R.style.dialog);
        this.mContext = context;
        this.isCancelAble = isCancelAble;
        mGravity = gravity;
        Log.e("art","myyyyyyyyyyyyy");
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        //点击外部是否关闭
        setCanceledOnTouchOutside(isCancelAble);
        //是否可以返回关闭
        setCancelable(isCancelAble);
        Window window = getWindow();
        WindowManager.LayoutParams wlp = window.getAttributes();
        DisplayMetrics displaysMetrics = new DisplayMetrics();
        window.getWindowManager().getDefaultDisplay().getMetrics(displaysMetrics);
        wlp.width = displaysMetrics.widthPixels;
        wlp.gravity = mGravity;
        if (wlp.gravity == Gravity.BOTTOM) {
            wlp.y = 0;
        }
        window.setAttributes(wlp);
    }
}
